#include "stdafx.h"
#include "GameAnalyze.h"
#include "Factory.h"
#include "DBDataMgr.h"
#include "GameStateMgr.h"


initialiseSingleton(CGameAnalyze);
bool CGameAnalyze::Init()
{
    m_dwLastNPCtime = 0;

    return true;
}

void CGameAnalyze::CalcWhere()
{
    CPlayer& Player = *IFactory::getSingleton().GetPlayer();
    sPos P = Player.GetPos();

    m_eWhere = E_BATTLE;
    VecPos& vGoback = GET_DB().m_vGoBackPath;
    VecPos& vPatrol = GET_DB().m_vPatrolPath;

    if (GET_DB().m_dwPatrolType==ENUM_RANDOM_PATROL || 
        /*GET_DB().m_dwPatrolType==ENUM_STAND_PATROL || */
        GET_DB().m_dwPatrolType==ENUM_FISH_PATROL )
    {
        m_eWhere = E_BATTLE;
        return;
    }

    if (vGoback.size()==0 || vPatrol.size()==0)
    {
        m_eWhere = E_BATTLE;
        return;
    }

    int n = GetNearestPoint(vGoback, 0, vGoback.size()-1, P);
    int m = GetNearestPoint(vPatrol, 0, vPatrol.size()-1, P);

    if (::CalcDistance3D(P, vGoback[n]) < ::CalcDistance3D(P, vPatrol[m]))
    {
        m_eWhere = E_CITY;
    }
    else
    {
        m_eWhere = E_BATTLE;
    }
}